package com.atguigu.tingshu.album.strategy;



import com.atguigu.tingshu.album.mapper.AlbumStatMapper;
import com.atguigu.tingshu.album.mapper.TrackInfoMapper;
import com.atguigu.tingshu.common.execption.GuiguException;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.model.order.OrderInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component("1002")
public class ProcessTrackPurchases implements ProcessDiffTypePurchases {
    @Autowired
    private TrackInfoMapper  trackInfoMapper;
    @Autowired
    private AlbumStatMapper  albumStatMapper;

    /**
     * 处理声音类型购买量(声音没有购买量,修改声音对应的专辑购买量)(数据库)
     * @param orderInfo 订单信息
     */
    @Override
    public void processTypePurchases(OrderInfo orderInfo) {
        Long trackId = orderInfo.getOrderDetailList().get(0).getItemId();
        //获取声音对应的专辑Id
        TrackInfo trackInfo = trackInfoMapper.selectById(trackId);
        if (trackInfo == null){
            throw  new GuiguException(201,"声音信息不存在");
        }
        Long albumId = trackInfo.getAlbumId();
        albumStatMapper.updateAlbumStatNum(albumId, "0403",orderInfo.getOrderDetailList().size());
    }
}
